<template>
  <a-modal
    width="850px"
    :zIndex="zIndex"
    :title="title"
    :visible="visible"
    :cancelText="$t('关闭')"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    v-drag
  >
    <template slot="footer">
      <a-row :gutter="24">
        <a-col :span="12">
          <div style="text-align: left" v-if="!dataForm.id && !isMeal">
            <a-checkbox v-model="isContinue" @change="changeAddState"></a-checkbox> {{ $t('连续添加') }}
          </div>
        </a-col>
        <a-col :span="12">
          <a-button @click="handleCancel" :disabled="confirmLoading">{{ $t('取消') }}</a-button>
          <a-button type="primary" @click="handleOk" v-if="!disable" :disabled="confirmLoading">{{
            $t('保存')
          }}</a-button>
        </a-col>
      </a-row>
    </template>
    <div style="height: 500px; overflow-y: auto; overflow-x: hidden">
      <a-row style="margin-left: 10px">
        <a-col :span="24">
          <a-form-model
            ref="dataForm"
            :rules="rules"
            :model="dataForm"
            :label-col="labelCol"
            :wrapper-col="wrapperCol"
            v-enterToNext
          >
            <a-row>
              <div style="margin: 0 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('基本信息') }}
              </div>
              <a-col :span="12">
                <a-form-model-item
                  prop="supplierId"
                  style="margin-bottom: 10px"
                  :label="$t('所属商户')"
                  v-if="stateDisable == 10"
                >
                  <a-select v-model="dataForm.supplierId">
                    <a-select-option value="">{{ $t('请选择') }}</a-select-option>
                    <a-select-option
                      v-for="(item, index) in supplierList"
                      :key="index"
                      :value="item.id"
                      :disabled="disable"
                      >{{ item.name }}</a-select-option
                    >
                  </a-select>
                </a-form-model-item>
                <a-form-model-item prop="code" style="margin-bottom: 10px" :label="$t('商品编码')">
                  <a-input v-model="dataForm.code" ref="code" :disabled="disable"></a-input>
                </a-form-model-item>
                <a-form-model-item prop="name" style="margin-bottom: 10px" :label="$t('商品名称')">
                  <a-input v-model="dataForm.name" :disabled="disable"></a-input>
                </a-form-model-item>
                <a-form-model-item prop="kind" style="margin-bottom: 10px" :label="$t('商品分类')">
                  <a-tree-select
                    show-search
                    :filterTreeNode="filterTreeNode"
                    :disabled="disable"
                    allowClear
                    v-model="dataForm.kind"
                    :dropdownStyle="{ maxHeight: '250px', overflow: 'auto' }"
                    :tree-data="treeData"
                    :placeholder="$t('请选择')"
                    :getPopupContainer="triggerNode => { return triggerNode.parentNode || document.body }"
                  />
                </a-form-model-item>
                <a-form-model-item style="margin-bottom: 10px" :label="$t('供应商')" v-if="stateDisable == 1">
                  <a-select v-model="dataForm.supplierId" :getPopupContainer="triggerNode => { return triggerNode.parentNode || document.body }">
                    <a-select-option value="">{{ $t('请选择') }}</a-select-option>
                    <a-select-option
                      v-for="(item, index) in supplierList"
                      :key="index"
                      :value="item.id"
                      :disabled="disable"
                      >{{ item.name }}</a-select-option
                    >
                  </a-select>
                </a-form-model-item>
                <a-form-model-item
                  prop="barCode"
                  style="margin-bottom: 10px"
                  :label="$t('条形码')"
                  v-if="stateDisable == 1 || stateDisable == 11"
                >
                  <a-input v-model="dataForm.barCode" :disabled="disable"></a-input>
                </a-form-model-item>
                <a-form-model-item
                  prop="unit"
                  style="margin-bottom: 10px"
                  :label="$t('单位')"
                  v-if="stateDisable == 1 || stateDisable == 11"
                >
                  <a-select
                    :placeholder="$t('请选择')"
                    v-model="dataForm.unit"
                    showSearch
                    :filter-option="false"
                    @search="onSearch"
                    :disabled="disable"
                  >
                    <div slot="dropdownRender" slot-scope="menu">
                      <div
                        style="padding: 4px 8px; cursor: pointer"
                        @mousedown="(e) => e.preventDefault()"
                        @click="addUnit"
                      >
                        <a-icon type="plus" /> {{ $t('添加') }}
                      </div>
                      <a-divider style="margin: 4px 0 0" />
                      <v-nodes :vnodes="menu" />
                    </div>
                    <a-select-option v-for="(item, i) in unitList" :key="i" :value="item.id">{{
                      item.name
                    }}</a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item
                  prop="standard"
                  style="margin-bottom: 10px"
                  :label="$t('规格')"
                  v-if="stateDisable == 1 || stateDisable == 11"
                >
                  <a-input v-model="dataForm.standard" :disabled="disable"></a-input>
                </a-form-model-item>
                <a-form-model-item
                  prop="cost"
                  style="margin-bottom: 10px"
                  :label="$t('参考成本')"
                  v-if="stateDisable != 10"
                >
                  <a-input-number v-model="dataForm.cost" :disabled="disable"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                                  :precision="2"
                  ></a-input-number>
                </a-form-model-item>
                <a-form-model-item
                  prop="realCoin2"
                  style="margin-bottom: 10px"
                  :label="$t('代币')"
                  v-if="stateDisable == 2"
                >
                  <a-input-number v-model="dataForm.realCoin2" :disabled="disable"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                  ></a-input-number>
                </a-form-model-item>
                <a-form-model-item
                  prop="presentCoin2"
                  style="margin-bottom: 10px"
                  :label="$t('赠送代币')"
                  v-if="stateDisable == 2"
                >
                  <a-input-number v-model="dataForm.presentCoin2" :disabled="disable"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                  ></a-input-number>
                </a-form-model-item>
                <a-form-model-item
                  prop="realCoin8"
                  style="margin-bottom: 10px"
                  :label="$t('游戏币')"
                  v-if="stateDisable == 8"
                >
                  <a-input-number v-model="dataForm.realCoin8" :disabled="disable"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                  ></a-input-number>
                </a-form-model-item>
                <a-form-model-item
                  prop="presentCoin8"
                  style="margin-bottom: 10px"
                  :label="$t('赠送游戏币')"
                  v-if="stateDisable == 8"
                >
                  <a-input v-model="dataForm.presentCoin8" :disabled="disable"

                                  style="width: 100%;"
                  ></a-input>
                </a-form-model-item>
                <a-form-model-item
                  prop="totalNumber"
                  style="margin-bottom: 10px"
                  :label="$t('有效次数')"
                  v-if="stateDisable == 3"
                >
                  <a-input-number v-model="dataForm.totalNumber" :disabled="disable"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                  ></a-input-number>
                </a-form-model-item>
                <a-form-model-item
                  prop="cost1"
                  style="margin-bottom: 10px"
                  :label="$t('结算价')"
                  v-if="stateDisable == 10"
                >
                  <a-input-number v-model="dataForm.cost1" :disabled="disable"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                                  :precision="2"
                  ></a-input-number>
                </a-form-model-item>
                <a-form-model-item
                  prop="referencePrice"
                  style="margin-bottom: 10px"
                  :label="$t('店面售价')"
                  v-if="stateDisable == 10"
                >
                  <a-input-number v-model="dataForm.referencePrice" :disabled="disable"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                                  :precision="2"
                  ></a-input-number>
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item
                  prop="allowOut"
                  style="margin-bottom: 5px"
                  v-if="stateDisable == 1 || stateDisable == 11"
                >
                  <a-checkbox :checked="dataForm.allowOut == 'Y'" :disabled="disable" @change="(e) => changeSelectState(e, 'allowOut', 2)">{{
                    $t('0库存允许出库')
                  }}</a-checkbox>
                </a-form-model-item>
                <a-row v-if="stateDisable == 1 || stateDisable == 11">
                  <a-col :span="8">
                    <a-form-model-item
                      :labelCol="{ span: 0 }"
                      :wrapperCol="{ span: 24 }"
                      prop="allowWarn"
                      style="margin-bottom: 5px"
                    >
                      <a-checkbox
                        :checked="dataForm.allowWarn == 'Y'"
                        :disabled="disable"
                        @change="(e) => changeSelectState(e, 'allowWarn', 2)"
                        >{{ $t('缺货提醒') }}</a-checkbox
                      >
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="14">
                    <a-form-model-item
                      prop="warnNum"
                      :labelCol="{ span: 14 }"
                      :wrapperCol="{ span: 10 }"
                      style="margin-bottom: 5px"
                      :label="$t('提醒数量')"
                    >
                      <a-input-number v-model="dataForm.warnNum" ref="warnNum" :disabled="dataForm.allowWarn == 'N'"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                </a-row>
                <a-form-model-item
                  prop="verifyType"
                  :label="$t('核销方式')"
                  :labelCol="{ span: 4 }"
                  :wrapperCol="{ span: 20 }"
                  v-if="stateDisable == 1"
                >
                  <a-radio-group v-model="dataForm.verifyType" :disabled="disable">
                    <a-radio style="line-height: 40px" :value="item.value" v-for="(item, index) in list" :key="index">{{
                      item.title
                    }}</a-radio>
                  </a-radio-group>
                </a-form-model-item>
                <a-col :span="24" style="padding-right: 0">
                  <a-form-model-item
                    prop="picture"
                    :label="$t('图片')"
                    :labelCol="{ span: 3 }"
                    :wrapperCol="{ span: 18 }"
                  >
                    <div>
                      <j-upload
                        v-model="dataForm.picture"
                        accept="jpg,jpeg,png,gif,webp"
                        fileType="image"
                        :disabled="disable"
                      ></j-upload>
                      <div style="color: #f7b926; line-height: 1.2">
                        {{ $t('建议尺寸：750*750，大小不要超过500KB') }}
                      </div>
                    </div>
                  </a-form-model-item>
                </a-col>
              </a-col>
              <a-col :span="24" v-if="stateDisable == 3 || stateDisable == 4">
                <a-row>
                  <a-col :span="11">
                    <a-form-model-item
                      prop="dayNumber"
                      :labelCol="{ span: 7 }"
                      :wrapperCol="{ span: 16 }"
                      style="margin: 0 0 10px -10px"
                      :label="$t('每日最大扣次数')"
                    >
                      <a-input-number v-model="dataForm.dayNumber" :disabled="disable"
                        :formatter="formatter"
                        :parser="parser"
                        style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8">
                    <span style="float: left; color: #efa44d; margin-top: 5px">{{ $t('（0表示不限制）') }}</span>
                  </a-col>
                </a-row>
              </a-col>
            </a-row>
            <a-row style="margin-left: 20px" v-if="stateDisable == 12">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('合成材料') }}
              </div>
              <a-col v-if="!disable">
                <a-table
                  :columns="setRawMaterialsTable.columns"
                  :dataSource="setRawMaterialsTable.dataSource"
                  bordered
                  class="customTable"
                  :pagination="false"
                  style="padding-left: 11px"
                >
                  <template slot="action" slot-scope="text, record">
                    <span v-if="text == $t('合计')">{{ text }}</span>
                    <a-icon v-else type="close" @click="deleteRaw(text, record)" />
                  </template>
                  <template slot="selectThree" slot-scope="text, record">
                    <div v-if="record.action == $t('合计')"></div>
                    <div v-else>
                      <a-select
                        v-model="record.materialId"
                        show-search
                        :placeholder="$t('请选择原材料')"
                        :filter-option="false"
                        style="width: 230px"
                        :not-found-content="null"
                        @search="handleMaterial"
                      >
                        <a-select-option v-for="good in addRawList" :key="good.id" @click="handleRaw(record, good)">{{
                          good.name
                        }}</a-select-option>
                      </a-select>
                    </div>
                  </template>
                  <template slot="inputAmount" slot-scope="text, record">
                    <div v-if="record.action == $t('合计')"></div>
                    <div v-else>
                      <a-input-number v-model="record.amount" @change="handleChangeRaw(record)"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                                      :precision="2"
                      ></a-input-number>
                    </div>
                  </template>
                </a-table>
              </a-col>
              <a-col v-if="disable">
                <a-table
                  :columns="setRawMaterialsTable.columns1"
                  :dataSource="setRawMaterialsTable.dataSource"
                  bordered
                  class="customTable"
                  :pagination="false"
                  style="padding-left: 11px"
                >
                </a-table>
              </a-col>
            </a-row>
            <a-row style="margin-left: 20px" v-if="stateDisable == 8">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('销售设置') }}
              </div>
              <a-col :span="24" style="margin-left: 10px">
                <a-row>
                  <a-col :span="6" v-if="taxSetting == 1">
                    <a-form-model-item prop="allowTax" style="margin-bottom: 5px">
                      <a-checkbox :checked="dataForm.allowTax == 1" :disabled="disable" @change="(e) => changeSelectState(e, 'allowTax', 1)">{{
                        $t('销售加税')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="allowSale" style="margin-bottom: 5px">
                      <a-checkbox :checked="dataForm.allowSale == 'Y'" :disabled="disable" @change="(e) => changeSelectState(e, 'allowSale', 2)">{{ $t('允许销售') }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="price" style="margin-bottom: 5px" :label="$t('售价')">
                      <a-input-number v-model="dataForm.price" :disabled="disable" @change="changePrice"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                                      :precision="2"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6" v-if="taxSetting == 2">
                    <a-form-model-item prop="taxPrice" style="margin-bottom: 5px" :label="$t('其中税费')" :labelCol="{ span: 8 }" :wrapperCol="{ span: 15 }">
                      <span>{{ dataForm.taxPrice }}</span>
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-col>
            </a-row>
            <a-row style="margin-left: 20px" v-if="stateDisable != 8 && stateDisable != 11">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('销售兑换设置') }}
              </div>
              <a-col :span="24">
                <a-row>
                  <a-col :span="6">
                    <a-form-model-item prop="allowMemberDiscount" style="margin-bottom: 5px" :labelCol="{ span: 0 }" :wrapperCol="{ span: 22 }">
                      <a-checkbox :checked="dataForm.allowMemberDiscount == 'Y'" :disabled="disable" @change="(e) => changeSelectState(e, 'allowMemberDiscount', 2)">{{
                        $t('享受会员优惠')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6" v-if="taxSetting == 1">
                    <a-form-model-item prop="allowTax" style="margin-bottom: 5px;margin-left: 10px" :labelCol="{ span: 0 }" :wrapperCol="{ span: 22 }">
                      <a-checkbox :checked="dataForm.allowTax == 1" :disabled="disable" @change="(e) => changeSelectState(e, 'allowTax', 1)">{{
                        $t('销售加税')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-col>
              <a-col :span="24">
                <a-row>
                  <a-col :span="6">
                    <a-form-model-item prop="allowSale" style="margin-bottom: 5px">
                      <a-checkbox :checked="dataForm.allowSale == 'Y'" :disabled="disable" @change="(e) => changeSelectState(e, 'allowSale', 2)">{{ $t('允许销售') }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="price" style="margin-bottom: 5px" :label="$t('售价')">
                      <a-input-number v-model="dataForm.price" :disabled="disable" @change="changePrice"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                                      :precision="2"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6" v-if="taxSetting == 2">
                    <a-form-model-item prop="taxPrice" style="margin-bottom: 5px" :label="$t('其中税费')" :labelCol="{ span: 8 }" :wrapperCol="{ span: 16 }">
                      {{dataForm.taxPrice}}
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6" v-if="taxSetting == 2">
                    <a-form-model-item prop="taxPrice" style="margin-bottom: 5px; opacity: 0" :label="$t('其中税费')" :labelCol="{ span: 8 }" :wrapperCol="{ span: 16 }">
                      <a-input-number v-model="dataForm.taxPrice" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                                      :precision="2"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6" v-if="stateDisable != 2">
                    <a-form-model-item prop="allowCoin" style="margin-bottom: 5px">
                      <a-checkbox :checked="dataForm.allowCoin == 'Y'" :disabled="disable" @change="(e) => changeSelectState(e, 'allowCoin', 2)">{{ $t('允许币兑换') }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6" v-if="stateDisable != 2">
                    <a-form-model-item prop="coin" style="margin-bottom: 5px" :label="$t('代币')">
                      <a-input-number v-model="dataForm.coin" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="allowLottery" style="margin-bottom: 5px">
                      <a-checkbox :checked="dataForm.allowLottery == 'Y'" :disabled="disable" @change="(e) => changeSelectState(e, 'allowLottery', 2)">{{
                        $t('允许彩票兑换')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="lottery" :label="$t('彩票')" style="margin-bottom: 5px">
                      <a-input-number v-model="dataForm.lottery" ref="lottery" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="allowPoints" style="margin-bottom: 5px">
                      <a-checkbox :checked="dataForm.allowPoints == 'Y'" :disabled="disable" @change="(e) => changeSelectState(e, 'allowPoints', 2)" style="width: 110%">{{ $t('允许A币兑换') }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="points" style="margin-bottom: 5px" :label="$t('A币')">
                      <a-input-number v-model="dataForm.points" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="allowIntegral" style="margin-bottom: 5px">
                      <a-checkbox :checked="dataForm.allowIntegral == 'Y'" :disabled="disable" @change="(e) => changeSelectState(e, 'allowIntegral', 2)">{{
                        $t('允许积分兑换')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="integral" style="margin-bottom: 5px" :label="$t('积分')">
                      <a-input-number v-model="dataForm.integral" ref="integral" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item
                      prop="allowAlottery"
                      :labelCol="{ span: 8 }"
                      :wrapperCol="{ span: 16 }"
                      style="margin-bottom: 5px"
                    >
                      <a-checkbox :checked="dataForm.allowAlottery == 'Y'" :disabled="disable" @change="(e) => changeSelectState(e, 'allowAlottery', 2)">{{
                        $t('允许A票兑换')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="alottery" style="margin-bottom: 5px" :label="$t('A票')">
                      <a-input-number v-model="dataForm.alottery" ref="alottery" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-col>
            </a-row>
            <a-row style="margin-left: 20px" v-if="stateDisable == 1">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('回收设置') }}
              </div>
              <a-col :span="24">
                <div>
                  <div style="margin-bottom: 10px" v-for="(item, index) in recycleList" :key="index">
                    <a-checkbox
                      style="padding-top: 6px; color: black; font-weight: 500; font-size: 15px"
                      :checked="item.status == 'Y'"
                      @change="(e) => changeStatus(e, index)"
                      :disabled="disable"
                      >{{ $t('允许回收') }}</a-checkbox
                    >
                    <span style="padding-left: 20px">{{ $t('回收类型') }}：</span>
                    <a-select
                      :placeholder="$t('请选择')"
                      v-model="item.recyclingType"
                      style="width: 200px"
                      :disabled="disable || item.status == 'N'"
                    >
                      <a-select-option v-for="type in paytypeList" :key="type.name" :value="type.name">
                        <span>{{ type.name_dictText }}</span>
                      </a-select-option>
                    </a-select>
                    <span style="padding-left: 20px">{{ $t('回收值') }}：</span>
                    <a-input-number
                      v-model="item.recyclingValue"
                      style="width: 140px"
                      :disabled="disable || item.status == 'N'"
                      :formatter="formatter"
                      :parser="parser"
                      :min="1"
                      :precision="0"
                    ></a-input-number>
                  </div>
                </div>
              </a-col>
            </a-row>
            <a-row style="margin-left: 20px">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('更多设置') }}
              </div>
              <a-row v-if="stateDisable == 3 || stateDisable == 4">
                <a-col :span="2">{{ $t('有效期') }}:</a-col>
                <a-col :span="22">
                  <a-form-model-item prop="validityType" :labelCol="{ span: 0 }" :wrapperCol="{ span: 22 }">
                    <a-radio-group v-model="dataForm.validityType" ref="validityType">
                      <div>
                        <a-radio value="0" style="width: 88px" :disabled="disable">{{ $t('不限期') }}</a-radio>
                      </div>
                      <div style="margin-top: 14px">
                        <a-radio value="1" style="width: 88px" :disabled="disable">{{ $t('指定日期') }}：</a-radio>
                        <j-date
                          :disabled="dataForm.validityType != '1'"
                          v-model="dataForm.startDate"
                          :placeholder="$t('请选择日期')"
                          style="width: 180px"
                        ></j-date>
                        ~
                        <j-date
                          :disabled="dataForm.validityType != '1'"
                          v-model="dataForm.endDate"
                          :placeholder="$t('请选择日期')"
                          style="width: 180px"
                        ></j-date>
                      </div>
                      <div style="margin-top: 14px">
                        <a-radio value="2" style="width: 88px" :disabled="disable">{{ $t('指定天数') }}：</a-radio>
                        {{ $t('领取后') }}
                        <i18n path="valid-period2" tag="span">
                          <a-input-number
                            place="startDays"
                            v-model="dataForm.startDays"
                            style="width: 64px; margin: 0 4px"
                            :disabled="disable"
                            :min="0"

                            :formatter="formatter"
                                  :parser="parser"

                          />
                          <a-input-number
                            place="validDays"
                            v-model="dataForm.validDays"
                            style="width: 64px; margin: 0 4px"
                            :disabled="disable"
                            :min="0"

                            :formatter="formatter"
                                  :parser="parser"
                          />
                        </i18n>
                      </div>
                      <!-- <div style="margin-top: 14px">
                        <a-radio value="3" style="width: 88px" :disabled="disable">{{ $t('会员续购：') }}</a-radio>
                        {{ $t('购买后从已有的该门票有效截止日期开始生效，有效期') }}
                        <a-input-number
                          :disabled="dataForm.validityType!='3'"
                          v-if="!disable"
                          v-model="dataForm.startDays"
                          style="width: 80px; margin-right: 10px"
                          :min="0"
                        ></a-input-number>
                        {{ $t('天') }}
                      </div> -->
                    </a-radio-group>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="9">
                  <a-form-model-item prop="state" style="margin-bottom: 5px" :label="$t('上架状态')">
                    <a-radio-group v-model="dataForm.state" ref="state" :disabled="disable">
                      <a-radio value="Y">{{ $t('上架') }}</a-radio>
                      <a-radio value="N">{{ $t('下架') }}</a-radio>
                    </a-radio-group>
                  </a-form-model-item>
                </a-col>
                <a-col :span="9">
                  <a-form-model-item style="margin-bottom: 5px">
                    <a-checkbox :checked="dataForm.authSale == 1" :disabled="disable" @change="(e) => changeSelectState(e, 'authSale', 1)">{{ $t('授权销售') }}</a-checkbox>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row v-if="stateDisable != 8 && stateDisable != 10 && stateDisable != 11">
                <a-col :span="9">
                  <a-form-model-item prop="limitCycle" style="margin-bottom: 5px" :label="$t('限购类型')">
                    <j-dict-select-tag
                      :placeholder="$t('请选择')"
                      style="width: 100px"
                      v-model="dataForm.limitCycle"
                      @change="changelimitCycleState"
                      :disabled="disable"
                      dictCode="bis_goods_infor.limit_cycle"
                    />
                  </a-form-model-item>
                </a-col>
                <a-col :span="7" style="margin-left: -110px">
                  <a-form-model-item
                    prop="limitNum"
                    :labelCol="{ span: 7 }"
                    :wrapperCol="{ span: 16 }"
                    style="margin-bottom: 0px"
                    :label="$t('限购数量')"
                  >
                    <a-input-number v-model="dataForm.limitNum" :disabled="limitCycledisable"

                                    :formatter="formatter"
                                  :parser="parser"
                                    style="width: 100%;"
                    ></a-input-number>
                  </a-form-model-item>
                </a-col>
                <a-col :span="10">
                  <div style="color: #f6aa64; margin-top: 5px">
                    {{ $t('(每个会员在特定的限购周期内最大允许的购买数量)') }}
                  </div>
                </a-col>
              </a-row>
              <a-row>
                <a-col v-if="stateDisable != 8 && stateDisable != 10 && stateDisable != 11">
                  <a-form-model-item
                    prop="allowMemberType"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 5px; margin-left: 4px"
                    :label="$t('适用会员')"
                  >
                    <a-radio-group
                      v-model="allowMemberType"
                      @change="getTypeValue"
                      :disabled="disable"
                      style="margin-left: 5px"
                    >
                      <a-radio value="">{{ $t('全部') }}</a-radio>
                      <a-radio value="part">{{ $t('指定会员') }}</a-radio> </a-radio-group
                    ><br />
                    <a-checkbox-group
                      :span="24"
                      v-if="memberShow"
                      v-model="dataForm.allowMemberTypes"
                      style="margin-top: 6px; margin-left: 5px"
                    >
                      <a-checkbox style="margin-left: 8px" :value="item.id" v-for="item in memberList" :key="item.id">{{
                        item.name
                      }}</a-checkbox>
                    </a-checkbox-group>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row v-if="stateDisable != 10 && stateDisable != 11">
                <a-col>
                  <a-form-model-item
                    prop="allowDeviceType"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 5px; margin-left: 4px"
                    :label="$t('适用渠道')"
                  >
                    <a-radio-group
                      v-model="allowDeviceType"
                      @change="getDeviceTypeValue"
                      :disabled="disable"
                      style="margin-left: 5px"
                    >
                      <a-radio value="">{{ $t('全部') }}</a-radio>
                      <a-radio value="part">{{ $t('指定渠道') }}</a-radio>
                    </a-radio-group>
                    <br />
                    <a-checkbox-group
                      v-if="deviceTypeShow"
                      v-model="dataForm.allowDeviceTypes"
                      style="margin-top: 6px; margin-left: 5px"
                      :disabled="disable"
                      @change="getDeviceList"
                    >
                      <a-checkbox
                        style="margin-left: 8px"
                        :value="item.type"
                        v-for="item in deviceTypeList"
                        :key="item.type"
                        >{{ item.type_dictText }}
                      </a-checkbox>
                    </a-checkbox-group>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row v-if="stateDisable != 10 && stateDisable != 11">
                <a-col>
                  <a-form-model-item
                    prop="allowDevice"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 5px; margin-left: 4px"
                    :label="$t('销售终端')"
                  >
                    <a-radio-group
                      v-model="allowDevice"
                      @change="getDeviceValue"
                      :disabled="disable"
                      style="margin-left: 5px"
                    >
                      <a-radio value="">{{ $t('全部') }}</a-radio>
                      <a-radio value="part">{{ $t('指定终端') }}</a-radio>
                    </a-radio-group>
                    <br />
                    <a-checkbox-group
                      v-if="deviceShow"
                      v-model="dataForm.allowDevices"
                      style="margin-top: 6px; margin-left: 5px"
                      :disabled="disable"
                    >
                      <a-checkbox style="margin-left: 8px" :value="item.id" v-for="item in deviceList" :key="item.id"
                        >{{ item.name }}
                      </a-checkbox>
                    </a-checkbox-group>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row v-if="stateDisable == 8">
                <a-col :span="24">
                  <a-form-model-item
                    prop="comment"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    :label="$t('销售方式')"
                    style="margin-bottom: 5px; margin-left: 4px"
                  >
                    <a-radio-group
                      v-model="allowPayType"
                      @change="getPaytypeValue"
                      :disabled="disable"
                      style="margin-left: 5px"
                    >
                      <a-radio value="">{{ $t('全部') }}</a-radio>
                      <a-radio value="part">{{ $t('指定支付方式') }}</a-radio>
                    </a-radio-group>
                    <br />
                    <a-checkbox-group
                      v-if="paytypeShow"
                      v-model="dataForm.allowPayTypes"
                      style="margin-top: 6px; margin-left: 5px"
                      :disabled="disable"
                    >
                      <a-checkbox style="margin-left: 8px" :value="item.name" v-for="item in payTypeList" :key="item.name"
                        >{{ item.nameText }}
                      </a-checkbox>
                    </a-checkbox-group>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item
                    prop="comment"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    :label="$t('商品简介')"
                    style="margin-left: 4px"
                  >
                    <a-textarea v-model="dataForm.comment" ref="comment" :rows="2" :disabled="disable" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row v-if="stateDisable != 11">
                <a-col :span="24">
                  <a-form-model-item
                    prop="details"
                    :label="$t('商品详情')"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-left: 4px"
                  >
                    <div style="color: #e28909">
                      {{
                        $t('用于小程序商品详情的展示；建议图片宽度375px，上传多张图片时，每张图片的宽度应该保持一致。')
                      }}
                    </div>
                    <j-upload
                      v-model="dataForm.details"
                      accept="jpg,jpeg,png,gif,webp"
                      fileType="image"
                      :disabled="disable"
                      class="detail-upload"
                      text="upload"
                    ></j-upload>
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
            <!-- <a-row style="margin-left: 20px" v-if="stateDisable != 11">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('第三方核销') }}
              </div>
              <a-form-model-item>
                <div style="display: inline-block" v-for="(item, index, key) in dataForm.bisGoodsThirdList" :key="key">
                  {{ item.channel_dictText }}: {{ item.thirdCode }}
                  <a-icon
                    @click="delGoodsThird(item, index, 'exclude')"
                    style="color: #1890ff; cursor: pointer"
                    type="close"
                    :disabled="disable"
                    v-if="!disable"
                  />，
                </div>
                <span>
                  <a href="javascript:void(0);" @click="addGoodsThird()" style="margin-left: 10px" v-if="!disable">{{
                    $t('添加')
                  }}</a>
                </span>
              </a-form-model-item>
            </a-row> -->
            <a-row
              style="margin-left: 20px"
              v-if="stateDisable == 2 || stateDisable == 3 || stateDisable == 4 || stateDisable == 5"
            >
              <div style="margin: 0 0 10px -30px">
                <a-checkbox
                  style="padding-top: 6px; color: black; font-weight: 500; font-size: 15px"
                  :checked="chargeAfter"
                  @change="changeChargeStatue"
                  >{{ $t('充值后晋级') }}</a-checkbox
                >
              </div>
              <a-col :span="24">
                <div>
                  <div style="margin-bottom: 10px" v-for="(item, index) in elevation" :key="index">
                    <a-select
                      :placeholder="$t('请选择晋级前会员类型')"
                      v-model="item.memberType"
                      style="width: 200px; margin-left: 8px"
                      :disabled="item.disable"
                    >
                      <a-select-option v-for="level in levelList" :key="level.id" :value="level.id">
                        <span>{{ level.level }}{{ level.name }}</span>
                      </a-select-option>
                    </a-select>
                    <span style="margin-left: 8px">{{ $t('晋级到') }}</span>
                    <a-select
                      :placeholder="$t('请选择晋级后会员类型')"
                      v-model="item.memberTypeAfter"
                      style="width: 200px; margin-left: 8px"
                      :disabled="item.disable"
                    >
                      <a-select-option v-for="level in levelList" :key="level.id" :value="level.id">
                        <span>{{ level.level }}{{ level.name }}</span>
                      </a-select-option>
                    </a-select>
                    <a href="javascript:void(0);" style="margin-left: 8px" v-if="item.disable"
                      ><a-icon type="edit" @click="editElevation(index)"
                    /></a>
                    <a href="javascript:void(0);" style="margin-left: 8px" v-else
                      ><a-icon type="check" @click="saveElevation(item, index)"
                    /></a>
                    <a href="javascript:void(0);" style="margin-left: 8px"
                      ><a-icon type="close" @click="deleteElevation(index)"
                    /></a>
                  </div>
                  <a href="javascript:void(0);" @click="addElevation" style="line-height: 32px; margin-left: 10px">{{
                    $t('添加')
                  }}</a>
                </div>
              </a-col>
              <div style="margin: 0 0 10px -30px">
                <a-checkbox style="padding-top: 6px" :checked="renewalAfter" @change="changeRenewalStatue">{{
                  $t('充值后续期')
                }}</a-checkbox>
                <span v-for="(item, index) in renewalList" :key="index">
                  <j-dict-select-tag
                    :placeholder="$t('请选择')"
                    style="width: 100px"
                    v-model="item.type"
                    :disabled="disable"
                    dictCode="bis_member_rule_renewal.type"
                  />
                  <span style="margin-left: 8px">{{ $t('开始续期') }}</span>
                  <a-input v-model="item.renewal" style="width: 140px; margin-left: 8px"></a-input>
                  <span style="margin-left: 8px">{{ $t('月') }}</span>
                </span>
              </div>
              <div
                style="margin: 0 0 10px -30px"
                v-if="dataForm.form == 2 || dataForm.form == 3 || dataForm.form == 4 || dataForm.form == 14"
              >
                <a-checkbox style="padding-top: 6px" v-model="dataForm.freeWithRecharge">{{
                  $t('开卡直接购买免收押金')
                }}</a-checkbox>
              </div>
            </a-row>
            <a-row
              style="margin-left: 20px"
              v-if="!dataForm.id && stateDisable == 1 && isStockIn == 1"
            >
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('入库管理') }}
              </div>
              <a-col :offset="1" :span="22" style="display: flex; align-items: center">
                <span style="white-space: nowrap; padding-right: 4px">{{ $t('仓库') }}:</span>
                <a-tree-select
                  allowClear
                  v-model="dataForm.store"
                  :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
                  :tree-data="storeData"
                  :placeholder="$t('请选择')"
                  style="width: 240px"
                />
                <a-button type="link" v-has="'BisGoodsStoreController:add'" @click="handleAdd">+{{$t('新增')}}</a-button>
                <span style="white-space: nowrap; padding-right: 4px">{{ $t('入库数量') }}:</span>
                <a-input-number
                  :formatter="formatter"
                  :parser="parser"
                  ref="number"
                  v-model="dataForm.stock"
                  style="width: 100%"
                />
              </a-col>
            </a-row>
          </a-form-model>
        </a-col>
      </a-row>
    </div>
    <add-unit-modal ref="unitModal" @ok="updateUnit"></add-unit-modal>
    <!-- <bis-goods-third-modal ref="goodsThirdmodel" @ok="addGoodsThirdCallback"></bis-goods-third-modal> -->
    <bisGoodsStore-modal ref="modalForm" @ok="modalFormOk"></bisGoodsStore-modal>
  </a-modal>
</template>

<script>
import Vue from 'vue'
import { TENANT_ID } from '@/store/mutation-types'
import { httpAction, getAction, isEmpty } from '@/api/manage'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
/* import BisGoodsThirdModal from './BisGoodsThirdModal' */
import AddUnitModal from './AddUnitModal'
import BisGoodsStoreModal from './BisGoodsStoreModal'
import {formatter, parser} from "@api/comm";
let that
export default {
  name: 'GoodsInfoModal',
  components: {
    /* BisGoodsThirdModal, */
    AddUnitModal,
    BisGoodsStoreModal,
    VNodes: {
      functional: true,
      render: (h, ctx) => ctx.props.vnodes,
    },
  },
  data() {
    return {
      formatter,
      parser,
      zIndex: 1001,
      title: '',
      confirmLoading: false,
      dataForm: {
        code: '',
        name: '',
        allowOut: 'N',
        allowWarn: 'N',
        warnNum: 0,
        verifyType: '1',
        allowMemberDiscount: 'N',
        allowTax: 1,
        allowCoin: 'N',
        allowLottery: 'N',
        allowPoints: 'N',
        allowSale: 'N',
        allowIntegral: 'N',
        allowAlottery: 'N',
        authSale: 1,
        state: '',
        allowMemberType: '',
        allowDeviceType: '',
        allowDevice: '',
        form: '', //形态
        bisGoodsPackageList: [],
        validityType: '0',
        /* bisGoodsThirdList: [], */
        freeWithRecharge: false,
      },
      treeData: [],
      deviceTypeShow: false,
      deviceShow: false,
      paytypeShow: false,
      memberShow: false,
      visible: false,
      labelCol: {
        xs: { span: 20 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 20 },
        sm: { span: 15 },
      },
      rules: {
        supplierId: [{ required: true, message: this.$t('请选择') }],
        name: [{ required: true, message: this.$t('请输入卖品名称') }],
        kind: [{ required: true, message: this.$t('请选择卖品分类') }],
        cost: [
          { required: true, message: this.$t('请输入卖品参考成本') },
          { pattern: /^\d+.?\d{0,2}$/, message: this.$t('小数点后最多输入两位') },
        ],
        realCoin2: [{ pattern: /^\d+.?\d{0,2}$/, message: this.$t('小数点后最多输入两位') }],
        presentCoin2: [{ pattern: /^\d+.?\d{0,2}$/, message: this.$t('小数点后最多输入两位') }],
        price: [{ pattern: /^\d+.?\d{0,2}$/, message: this.$t('小数点后最多输入两位') }],
        integral: [{ pattern: /^[+]{0,1}(\d+)$/, message: this.$t('请输入0或正整数') }],
        lottery: [{ pattern: /^[+]{0,1}(\d+)$/, message: this.$t('请输入0或正整数') }],
        alottery: [{ pattern: /^[+]{0,1}(\d+)$/, message: this.$t('请输入0或正整数') }],
        points: [{ pattern: /^\d+.?\d{0,2}$/, message: this.$t('小数点后最多输入两位') }],
        realCoin8: [{ pattern: /^[+]{0,1}(\d+)$/, message: this.$t('请输入0或正整数') }],
        presentCoin8: [{ pattern: /^[+]{0,1}(\d+)$/, message: this.$t('请输入0或正整数') }],
        referencePrice: [{ required: true, message: this.$t('请输入店面售价') }],
        cost1: [{ required: true, message: this.$t('请输入结算价') }],
      },
      dataSource: [],
      memberList: [],
      deviceTypeList: [],
      deviceList: [],
      url: {
        add: '/goods/bisGoodsInfor/add',
        edit: '/goods/bisGoodsInfor/edit',
        importExcelUrl: '/sys/common/upload',
      },
      disable: false,
      limitCycledisable: false,
      allowWarnsdisable: true,
      list: [],
      allowMemberType: '',
      allowDevice: '',
      allowPayType: '',
      allowDeviceType: '',
      stateDisable: '',
      taxSetting: 0,
      goodsFormList: [],
      addGoodsListTwo: [],
      supplierList: [], //供应商

      //现调
      addRawList: [],
      setRawMaterialsTable: {
        loading: false,
        dataSource: [],
        rawMaterialsList: [],
        goodsList: [],
        columns: [
          {
            title: '+',
            dataIndex: 'action',
            align: 'center',
            width: 100,
            customHeaderCell: function (column) {
              return {
                style: {
                  textAlign: 'center',
                  color: '#1890ff',
                  fontSize: '25px',
                  height: '32px',
                  lineHeight: '32px',
                  fontWeight: 'bold',
                  cursor: 'pointer',
                },
                on: {
                  click: () => {
                    that.addRaws()
                  },
                },
              }
            },
            customCell: function (column) {
              return {
                style: {
                  textAlign: 'center',
                  color: '#1890ff',
                  fontSize: '16px',
                  height: '32px',
                  lineHeight: '32px',
                  fontWeight: 'bold',
                  cursor: 'pointer',
                },
              }
            },
            scopedSlots: { customRender: 'action' },
          },
          {
            title: this.$t('原材料'),
            align: 'center',
            dataIndex: 'materialId_dictText',
            scopedSlots: { customRender: 'selectThree' },
          },
          {
            title: this.$t('参考成本'),
            align: 'center',
            dataIndex: 'cost',
          },
          {
            title: this.$t('数量'),
            align: 'center',
            dataIndex: 'amount',
            scopedSlots: { customRender: 'inputAmount' },
          },
          {
            title: this.$t('合计成本'),
            align: 'center',
            dataIndex: 'amountCost',
          },
        ],
        columns1: [
          {
            title: this.$t('原材料'),
            align: 'center',
            dataIndex: 'materialId_dictText',
          },
          {
            title: this.$t('参考成本'),
            align: 'center',
            dataIndex: 'cost',
          },
          {
            title: this.$t('数量'),
            align: 'center',
            dataIndex: 'amount',
          },
          {
            title: this.$t('合计成本'),
            align: 'center',
            dataIndex: 'amountCost',
          },
        ],
      },
      goodsPriceRule: {
        isGoodsPriceRule: 0,
        coinRule: 1,
        lotteryRule: 1,
        integralRule: 1,
        pointsRule: 1,
        alotteryRule: 1,
      },
      levelList: [],
      elevation: [],
      chargeAfter: false,
      renewalList: [],
      renewalAfter: false,
      unitList: [],
      isContinue: true,
      isMeal: false,
      tenantid: Vue.ls.get(TENANT_ID),
      paytypeList: [],
      recycleList: [],
      isStockIn: localStorage.getItem('newStockIn'),
      storeData: []
    }
  },
  created() {
    that = this
  },
  methods: {
    handleAdd(){
      this.$refs.modalForm.add();
      this.$refs.modalForm.title = this.$t('新增');
      this.$refs.modalForm.disableSubmit = false;
    },
    modalFormOk(id){
      this.getStore()
      this.$set(this.dataForm,'store',id)
    },
    getStore() {
      let that = this
      let param = {}
      param.pageNo = 1
      param.pageSize = 9999
      param.column = 'createTime'
      param.order = 'desc'
      param.tenantId = that.tenantid ? that.tenantid : 0
      getAction('/goods/bisGoodsStore/rootList', param).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            res.result.records.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.id = '' + col.id
              col.pid = '' + col.pid
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChildStore(col)
              }
            })
            that.storeData = that.getDataByResult(res.result.records)
          } else {
            that.storeData = []
          }
        } else {
          that.$alert(res.message, that.$t('提示'), {
            confirmButtonText: that.$t('确定'),
            callback: (action) => {},
          })
        }
      })
    },
    getHasChildStore(record) {
      let that = this
      let query = {}
      query.pageNo = 1
      query.pageSize = 9999
      query.pid = record.id
      query.column = 'createTime'
      query.order = 'desc'
      query.tenantId = that.tenantid ? that.tenantid : 0
      getAction('/goods/bisGoodsStore/rootList', query).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            res.result.records.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.pid = '' + col.pid
              col.id = '' + col.id
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChild(col)
              }
            })
            record.children = that.getDataByResult(res.result.records)
            that.storeData = [...that.storeData]
          }
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    /* addGoodsThird() {
      that.$refs.goodsThirdmodel.edit()
    },
    delGoodsThird(item) {
      that.dataForm.bisGoodsThirdList.forEach((col) => {
        if (col.channel == item.channel && col.thirdCode == item.thirdCode) {
          let index = that.dataForm.bisGoodsThirdList.indexOf(col)
          that.dataForm.bisGoodsThirdList.splice(index, 1)
        }
      })
    },
    addGoodsThirdCallback(item) {
      getAction('/sys/dict/getDictText/bis_goods_third.channel/' + item.channel).then((res) => {
        if (res.success) {
          item.channel_dictText = res.result
          var b = true
          if (that.dataForm.bisGoodsThirdList && that.dataForm.bisGoodsThirdList.length > 0) {
            that.dataForm.bisGoodsThirdList.forEach((col) => {
              if (col.channel == item.channel && col.thirdCode == item.thirdCode) {
                b = false
                return
              }
            })
          } else {
            that.$set(that.dataForm, 'bisGoodsThirdList', [])
          }
          if (b) {
            that.dataForm.bisGoodsThirdList.push(item)
          } else {
            that.$message.warning('该第三方渠道商品已存在')
            return
          }
        }
      })
    }, */
    changeStatus(e, i) {
      that.$set(that.recycleList[i], 'status', e.target.checked ? 'Y' : 'N')
    },
    changePrice() {
      if (that.goodsPriceRule.isGoodsPriceRule == 1) {
        that.$set(that.dataForm, 'coin', that.dataForm.price * that.goodsPriceRule.coinRule)
        that.$set(that.dataForm, 'lottery', that.dataForm.price * that.goodsPriceRule.lotteryRule)
        that.$set(that.dataForm, 'integral', that.dataForm.price * that.goodsPriceRule.integralRule)
        that.$set(that.dataForm, 'points', that.dataForm.price * that.goodsPriceRule.pointsRule)
        that.$set(that.dataForm, 'alottery', that.dataForm.price * that.goodsPriceRule.alotteryRule)
      }
      if(that.taxSetting == 2){
        that.$set(that.dataForm,'taxPrice',(that.dataForm.price - (that.dataForm.price / ( 1 + localStorage.getItem('taxRate') / 100))).toFixed(2))
      }
    },
    getInfo() {
      getAction('/bis/bisSysParameter/list', { name: 'isGoodsPriceRule' }).then((res) => {
        if (res.success) {
          if (res.result.total > 0) {
            that.goodsPriceRule.isGoodsPriceRule = res.result.records[0].ivalue
            if (that.goodsPriceRule.isGoodsPriceRule == 1) {
              getAction('/bis/bisSysParameter/list', {
                name: 'coinRule,lotteryRule,integralRule,pointsRule,alotteryRule',
              }).then((res) => {
                if (res.success) {
                  if (res.result.total > 0) {
                    res.result.records.forEach((el) => {
                      if (el.name == 'coinRule') {
                        that.goodsPriceRule.coinRule = el.dvalue
                      }
                      if (el.name == 'lotteryRule') {
                        that.goodsPriceRule.lotteryRule = el.dvalue
                      }
                      if (el.name == 'integralRule') {
                        that.goodsPriceRule.integralRule = el.dvalue
                      }
                      if (el.name == 'pointsRule') {
                        that.goodsPriceRule.pointsRule = el.dvalue
                      }
                      if (el.name == 'alotteryRule') {
                        that.goodsPriceRule.alotteryRule = el.dvalue
                      }
                    })
                  }
                } else {
                  that.$message.error(res.message)
                }
              })
            }
          }
        } else {
          that.$message.error(res.message)
        }
      })
    },
    add(value, arg) {
      that.isContinue = localStorage.getItem('goodsAddInfo')
        ? JSON.parse(localStorage.getItem('goodsAddInfo')).state
        : true
      if (arg) {
        that.isMeal = true
      } else {
        that.isMeal = false
      }
      let record
      if (value == 1) {
        that.getStore()
        record = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: '',
          allowMemberDiscount: 'N',
          allowTax: 1,
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          species: '1',
          bisGoodsPackageList: [],
          supplierId: '',
          recyclingList: [{ status: 'N' }],
          store: '',
          stock: ''
        }
        that.isStockIn = localStorage.getItem('newStockIn')
        that.select()
      }else{
        that.isStockIn = 0
      }
      if (value == 2) {
        record = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: 0,
          allowMemberDiscount: 'N',
          allowTax: 1,
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
          bisGoodsPackageList: [],
          freeWithRecharge: false,
        }
        that.chargeAfter = false
        that.elevation = [
          {
            memberType: undefined,
            memberTypeAfter: undefined,
            disable: false,
          },
        ]
        that.renewalAfter = false
        that.renewalList = [
          {
            type: '0',
            renewal: '',
          },
        ]
      }
      if (value == 3) {
        record = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: 0,
          allowMemberDiscount: 'N',
          allowTax: 1,
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          totalNumber: '1',
          species: '1',
          bisGoodsPackageList: [],
          validityType: '0',
        }
        that.chargeAfter = false
        that.elevation = [
          {
            memberType: undefined,
            memberTypeAfter: undefined,
            disable: false,
          },
        ]
        that.renewalAfter = false
        that.renewalList = [
          {
            type: '0',
            renewal: '',
          },
        ]
      }
      if (value == 4) {
        record = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: 0,
          allowMemberDiscount: 'N',
          allowTax: 1,
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          species: '1',
          bisGoodsPackageList: [],
          validityType: '0',
          freeWithRecharge: false,
        }
        that.chargeAfter = false
        that.elevation = [
          {
            memberType: undefined,
            memberTypeAfter: undefined,
            disable: false,
          },
        ]
        that.renewalAfter = false
        that.renewalList = [
          {
            type: '0',
            renewal: '',
          },
        ]
      }
      if (value == 8) {
        record = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: 0,
          allowMemberDiscount: 'N',
          allowTax: 1,
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowPayTypes: [],
          allowPayType: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
          bisGoodsPackageList: [],
        }
      }
      if (value == 10) {
        record = {
          supplierId: '',
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          allowMemberDiscount: 'N',
          allowTax: 1,
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
          bisGoodsPackageList: [],
        }
      }
      if (value == 11) {
        record = {
          code: '',
          name: '',
          cost1: '',
          cost: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          allowSale: 'N',
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
        }
      }
      if (value == 12) {
        record = {
          code: '',
          name: '',
          cost1: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: '',
          allowMemberDiscount: 'N',
          allowTax: 1,
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
        }
      }
      that.edit(record)
    },
    edit(record, state) {
      if (record.id) {
        that.isMeal = false
        if (state === undefined) {
          that.title = that.$t('编辑')
        } else {
          that.title = that.$t('详情')
        }
      } else {
        that.title = that.$t('新增')
      }
      that.getInfo()
      that.stateDisable = record.form
      that.setRawMaterialsTable.dataSource = []
      that.disable = state
      that.getMemberList()
      that.getDeviceTypeList()
      that.taxSetting = localStorage.getItem('taxSetting')
      that.visible = true
      that.select()
      if (that.disable == true || record.limitCycle == '0') {
        that.limitCycledisable = true
      } else {
        that.limitCycledisable = false
      }
      if (record.allowWarn == 'Y' || that.disable == true) {
        that.allowWarnsdisable = true
      }
      if (record.form == 1 || record.form == 11) {
        that.onSearch()
      }
      if (record.form == 1) {
        initDictOptions('bis_goods_infor.verify_type').then((res) => {
          if (res.success) {
            that.list = res.result
          }
        })
        getAction('/pay/bisPayType/list', {
          pageNo: 1,
          pageSize: 9999,
          name: '6,7,10,11,12',
          state: 'Y',
          allowDeviceType: 'EF000000',
          column: 'sort',
          order: 'asc',
        }).then((res) => {
          if (res.success) {
            res.result.records.forEach((r) => {
              if (r.name_dictText.indexOf('payment') > -1) {
                r.name_dictText = r.name_dictText.split('payment')[0]
              } else {
                r.name_dictText = r.name_dictText.split('支付')[0]
              }
            })
            that.paytypeList = res.result.records
          } else {
            that.$message.error(res.message)
          }
        })
        that.getSupplier(0)
        if (record.recyclingList == null || record.recyclingList.length == 0) {
          record.recyclingList = [{ status: 'N' }]
        }
        let recycleList = JSON.parse(JSON.stringify([...record.recyclingList]))
        that.recycleList = recycleList
      }
      if (record.form == 2 || record.form == 3 || record.form == 4) {
        that.chargeAfter = record.allowPromote ? true : false
        that.renewalAfter = record.allowRenewal ? true : false
        that.getLevels()
      }
      if (record.form == 8){
        that.getPaytypeList()
        that.allowPayType = record.allowPayType?record.allowPayType:''
        if (that.allowPayType == '' || that.allowPayType == null || that.allowPayType == undefined) {
          that.paytypeShow = false
        } else {
          record.allowPayTypes = record.allowPayType.split(',')
          that.allowPayType = 'part'
          that.paytypeShow = true
        }
      }
      if (record.form == 10) {
        that.getSupplier(1)
      }
      if (record.form == 12) {
        if (record.id) {
          that.getRaw(record.id)
        } else {
          that.getGoodsListTwo(11)
        }
      }

      that.allowMemberType = record.allowMemberType
      if (that.allowMemberType == '' || that.allowMemberType == null || that.allowMemberType == undefined) {
        that.memberShow = false
      } else {
        record.allowMemberTypes = record.allowMemberType.split(',')
        that.allowMemberType = 'part'
        that.memberShow = true
      }

      that.allowDeviceType = record.allowDeviceType
      if (that.allowDeviceType == null || that.allowDeviceType == undefined) {
        that.allowDeviceType = ''
      }
      if (that.allowDeviceType == '') {
        that.deviceTypeShow = false
      } else {
        record.allowDeviceTypes = record.allowDeviceType.split(',')
        that.allowDeviceType = 'part'
        that.deviceTypeShow = true
      }

      that.allowDevice = record.allowDevice
      if (that.allowDevice == '' || that.allowDevice == null || that.allowDevice == undefined) {
        that.deviceShow = false
      } else {
        record.allowDevices = record.allowDevice.split(',')
        that.allowDevice = 'part'
        that.deviceShow = true
      }
      that.dataForm = Object.assign({}, record)
      if (that.dataForm.id && (record.form == 2 || record.form == 3 || record.form == 4)) {
        that.getGoodsMemberTypeList()
        that.getRenewal()
      }
      if (that.dataForm.id && that.dataForm.form == 1) {
      }
      that.$set(that.dataForm, 'realCoin2', that.dataForm.realCoin)
      that.$set(that.dataForm, 'realCoin8', that.dataForm.realCoin)
      that.$set(that.dataForm, 'presentCoin2', that.dataForm.presentCoin)
      that.$set(that.dataForm, 'presentCoin8', that.dataForm.presentCoin)
      that.$set(that.dataForm, 'cost1', that.dataForm.cost)
      that.getDeviceList()
    },
    getRenewal() {
      getAction('/goods/bisGoodsRenewal/list', { goodsId: that.dataForm.id }).then((res) => {
        if (res.success) {
          if (res.result.total > 0) {
            that.renewalList = res.result.records
          } else {
            that.renewalList = [
              {
                type: '0',
                renewal: '',
              },
            ]
          }
        }
      })
    },
    getLevels() {
      that.levelList = []
      getAction('/member/bisMemberRule/list', { notNonmember: 1, manageState: 'Y', pageSize: 40 }).then((res) => {
        if (res.success) {
          that.levelList = res.result.records
          return
        }
      })
    },
    getGoodsMemberTypeList() {
      getAction('/goods/bisGoodsMemberType/list', { goodsId: that.dataForm.id }).then((res) => {
        if (res.success) {
          if (res.result.total > 0) {
            res.result.records.forEach((rs) => {
              rs.disable = true
            })
            that.elevation = res.result.records
          } else {
            that.elevation = [
              {
                memberType: undefined,
                memberTypeAfter: undefined,
                disable: false,
              },
            ]
          }
        }
      })
    },
    getSupplier(type) {
      getAction('/goods/bisGoodsSupplier/list', { type: type, pageSize: 50 }).then((res) => {
        if (res.success) {
          that.supplierList = res.result.records
        }
      })
    },
    filterTreeNode(inputValue, treeNode) {
      // 假设输入格式为 "级别:关键词" 如 "2:电器"
      const match = inputValue.match(/([123]):(.+)/)
      if (match) {
        const level = parseInt(match[1])
        const keyword = match[2]
        const nodeLevel = this.getNodeLevel(treeNode)
        
        if (nodeLevel !== level) return false
        return treeNode.data.props.title.includes(keyword)
      }
      
      // 默认搜索
      return treeNode.data.props.title.includes(inputValue)
    },
    getNodeLevel(node) {
      let level = 1
      let parent = node.parent
      while (parent) {
        level++
        parent = parent.parent
      }
      return level
    },
    select() {
      let param = {}
      param.pageNo = 1
      param.pageSize = 9999
      param.column = 'sort'
      param.order = 'asc'
      if (!that.disable && !that.tenantid) {
        param.tenantId = 0
      }
      getAction('/goods/bisGoodsKind/rootList', param).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            res.result.records.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.id = '' + col.id
              col.pid = '' + col.pid
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChild(col)
              }
            })
            that.treeData = that.getDataByResult(res.result.records)
          } else {
            that.treeData = []
          }
        } else {
          that.$alert(res.message, that.$t('提示'), {
            confirmButtonText: that.$t('确定'),
            callback: (action) => {},
          })
        }
      })
    },
    getHasChild(record, arg) {
      let query = {}
      query.pageNo = 1
      query.pageSize = 9999
      query.pid = record.id
      if (!that.visible && !that.tenantid) {
        query.tenantId = 0
      }
      getAction('/goods/bisGoodsKind/rootList', query).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            res.result.records.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.pid = '' + col.pid
              col.id = '' + col.id
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChild(col)
              }
            })
            record.children = that.getDataByResult(res.result.records)
            that.treeData = [...that.treeData]
          }
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    getDataByResult(result) {
      return result.map((item) => {
        return item
      })
    },
    getGoodsListTwo(form, value) {
      let querydata = {}
      querydata.pageIndex = 1
      querydata.pageSize = 10
      querydata.form = form
      querydata.goodsInfo = value
      getAction('/goods/bisGoodsInfor/list', querydata).then((res) => {
        if (res.success) {
          that.addRawList = res.result.records
        }
      })
    },
    handleMaterial(value) {
      that.getGoodsListTwo(11, value)
    },
    addRaws() {
      let obj = {
        materialId: '',
        cost: '',
        amount: '',
        amountCost: '',
      }
      that.setRawMaterialsTable.dataSource.unshift(obj)
    },
    handleRaw(r, i) {
      r.cost = i.cost
    },
    handleChangeRaw(r) {
      r.amountCost = (r.cost * r.amount).toFixed(2)
      that.setRawMaterialsTable.dataSource.pop()
      that.addSumRow(['action', 'amountCost'], that.setRawMaterialsTable.dataSource)
    },
    deleteRaw(a, b) {
      that.setRawMaterialsTable.dataSource.forEach((col) => {
        if (col.materialId == b.materialId) {
          let index = that.setRawMaterialsTable.dataSource.indexOf(col)
          that.setRawMaterialsTable.dataSource.splice(index, 1)
        }
      })
      that.setRawMaterialsTable.dataSource.pop()
      that.addSumRow(['action', 'amountCost'], that.setRawMaterialsTable.dataSource)
    },
    getRaw(goodsId) {
      let query = {
        goodsId: goodsId,
      }
      getAction('/goods/bisGoodsMaterial/list', query).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            let arr = []
            res.result.records.forEach((col) => {
              let dtl = {
                id: col.materialId,
                name: col.materialId_dictText,
              }
              arr.push(dtl)
              col.cost = col.material.cost
              col.amountCost = (col.cost * col.amount).toFixed(2)
              that.setRawMaterialsTable.dataSource.push(col)
            })
            that.addRawList = arr
            that.addSumRow(['action', 'amountCost'], that.setRawMaterialsTable.dataSource)
          }
        }
      })
    },
    addSumRow(myArr, dataSource) {
      let total = {}
      myArr.forEach((col, index) => {
        if (index == 0) {
          total[col] = that.$t('合计')
        } else {
          total[col] = 0
        }
      })
      for (let key in total) {
        dataSource.forEach((ds) => {
          if (!isNaN(total[key])) {
            total[key] += Number(ds[key])
          }
        })
      }
      that.dataForm.cost = total.amountCost
      dataSource.push(total)
    },
    changelimitCycleState(e) {
      if (e == '0') {
        that.limitCycledisable = true
      } else {
        that.limitCycledisable = false
      }
    },
    getTypeValue(e) {
      if (e.target.value == 'part') {
        that.memberShow = true
      } else {
        that.memberShow = false
      }
    },
    getDeviceTypeValue(e) {
      if (e.target.value == 'part') {
        that.deviceTypeShow = true
      } else {
        that.deviceTypeShow = false
      }
    },
    getDeviceValue(e) {
      if (e.target.value == 'part') {
        that.deviceShow = true
      } else {
        that.deviceShow = false
      }
    },
    getPaytypeValue(e) {
      if (e.target.value == 'part') {
        that.paytypeShow = true
      } else {
        that.paytypeShow = false
      }
    },
    getMemberList() {
      getAction('/member/bisMemberRule/list').then((res) => {
        if (res.success) {
          that.memberList = res.result.records
        }
      })
    },
    getDeviceTypeList() {
      getAction('/device/bisDeviceInfo/getTypeList', { kind: 0 }).then((res) => {
        if (res.success) {
          that.deviceTypeList = res.result.records
        }
      })
    },
    getDeviceList() {
      let kind = 0
      let type = ''
      if (that.allowDeviceType == 'part') {
        if (that.dataForm.allowDeviceTypes) {
          type = that.dataForm.allowDeviceTypes.join(',')
        }
      }
      getAction('/device/bisDeviceInfo/nameList', {
        pageSize: 999,
        type: type,
        kind: kind,
        column: 'type',
        order: 'ASC',
      }).then((res) => {
        if (res.success) {
          that.deviceList = res.result.records
        }
      })
    },
    getPaytypeList() {
      getAction('/pay/bisPayType/nameList', {
        orderType: 0
      }).then((res) => {
        if (res.success) {
          console.log(res.result)
          that.payTypeList = res.result
        }
      })
    },
    close() {
      that.$emit('close')
      that.visible = false
    },
    handleOk() {
      let querydata = {}
      that.$refs.dataForm.validate((valid) => {
        if (valid) {
          if (that.dataForm.form == 2) {
            that.dataForm.presentCoin = that.dataForm.presentCoin2
            that.dataForm.realCoin = that.dataForm.realCoin2
          }
          if (that.dataForm.form == 8) {
            that.dataForm.realCoin = that.dataForm.realCoin8
            that.dataForm.presentCoin = that.dataForm.presentCoin8
          }
          if (that.dataForm.form == 3 || that.dataForm.form == 4) {
            if (that.dataForm.validityType == '1' && (!that.dataForm.startDate || !that.dataForm.endDate)) {
              that.$message.warn(that.$t('请设置指定日期'))
              return
            }
            if (that.dataForm.validityType == '2' && !that.dataForm.validDays) {
              that.$message.warn(that.$t('请设置指定天数'))
              return
            }
            if (that.dataForm.validityType == '2' && !that.dataForm.startDays) {
              that.dataForm.startDays = '0'
            }
          }
          if (
            that.dataForm.form == 2 ||
            that.dataForm.form == 3 ||
            that.dataForm.form == 4 ||
            that.dataForm.form == 5
          ) {
            if (that.chargeAfter) {
              that.dataForm.allowPromote = 1
              let arr = that.elevation.filter((el) => {
                return el.disable
              })
              if (arr.length == 0) {
                that.$message.warn(that.$t('至少设置一条晋级规则'))
                return
              }
            } else {
              that.dataForm.allowPromote = 0
            }
            if (that.renewalAfter) {
              that.dataForm.allowRenewal = 1
              let arr = that.renewalList.filter((el) => {
                return el.renewal === ''
              })
              if (arr.length > 0) {
                that.$message.warn(that.$t('请设置续期规则'))
                return
              }
              that.dataForm.renewalList = that.renewalList
            } else {
              that.dataForm.allowRenewal = 0
            }
          }
          if (that.dataForm.form == 10) {
            that.dataForm.cost = that.dataForm.cost1
          }
          if (that.dataForm.form == 12) {
            let materials = that.setRawMaterialsTable.dataSource
            if (materials.length == 0 || (materials.length == 1 && materials[0].action == that.$t('合计'))) {
              that.$message.warning(that.$t('请添加合成材料'))
              return
            }
            let arr1 = materials.filter((ml) => {
              return ml.action != '合计' && !ml.materialId
            })
            if (arr1.length > 0) {
              that.$message.warning(that.$t('请选择原材料'))
              return
            }
            let arr2 = materials.filter((ml) => {
              return ml.action != '合计' && !ml.amountCost
            })
            if (arr2.length > 0) {
              that.$message.warning(that.$t('请输入原材料数量'))
              return
            }
          }
          if (that.dataForm.name == '') {
            that.$message.warn(that.$t('请输入商品名称'))
            return
          }
          if (that.dataForm.allowLottery == 'Y' && (that.dataForm.lottery == undefined || that.dataForm.lottery === '')) {
            that.$message.warn(that.$t('彩票值不能为空'))
            return
          }
          if (that.dataForm.allowCoin == 'Y' && (that.dataForm.coin == undefined || that.dataForm.coin === '')) {
            that.$message.warn(that.$t('代币值不能为空'))
            return
          }
          if (that.dataForm.allowPoints == 'Y' && (that.dataForm.points == undefined || that.dataForm.points === '')) {
            that.$message.warn(that.$t('A币不能为空'))
            return
          }
          if(that.dataForm.allowSale == 'Y' && (that.dataForm.price == undefined || that.dataForm.price === '')) {
            that.$message.warn(that.$t('售价不能为空'))
            return
          }
          if (that.dataForm.allowIntegral == 'Y' && (that.dataForm.integral == undefined || that.dataForm.integral === '')) {
            that.$message.warn(that.$t('积分不能为空'))
            return
          }
          if (that.dataForm.allowAlottery == 'Y' && (that.dataForm.alottery == undefined || that.dataForm.alottery === '')) {
            that.$message.warn(that.$t('A票值不能为空'))
            return
          }
          if (that.dataForm.limitCycle != '0') {
            if (that.dataForm.limitNum == undefined || that.dataForm.limitNum === '') {
              that.$message.warn(that.$t('限购数量不能为空'))
              return
            }
          }
          if (that.allowMemberType == 'part') {
            if (that.dataForm.allowMemberTypes == null || that.dataForm.allowMemberTypes == '') {
              that.$message.warn(that.$t('请选择会员类型'))
              return
            }
            that.dataForm.allowMemberType = that.dataForm.allowMemberTypes.join(',')
          } else {
            that.dataForm.allowMemberType = ''
          }

          if (that.allowDeviceType == 'part') {
            if (that.dataForm.allowDeviceTypes == null || that.dataForm.allowDeviceTypes == '') {
              that.$message.warn(that.$t('请选择适用渠道'))
              return
            }
            that.dataForm.allowDeviceType = that.dataForm.allowDeviceTypes.join(',')
          } else {
            that.dataForm.allowDeviceType = ''
          }

          if (that.allowDevice == 'part') {
            if (that.dataForm.allowDevices == null || that.dataForm.allowDevices == '') {
              that.$message.warn(that.$t('请选择适用终端'))
              return
            }
            that.dataForm.allowDevice = that.dataForm.allowDevices.join(',')
          } else {
            that.dataForm.allowDevice = ''
          }
          if (that.allowPayType == 'part') {
            if (that.dataForm.allowPayTypes == null || that.dataForm.allowPayTypes == '') {
              that.$message.warn(that.$t('请选择销售方式'))
              return
            }
            that.dataForm.allowPayType = that.dataForm.allowPayTypes.join(',')
          } else {
            that.dataForm.allowPayType = ''
          }
          querydata = that.dataForm
          if (querydata.form == 1) {
            let x = that.recycleList.findIndex((rl) => {
              return rl.status == 'Y' && isEmpty(rl.recyclingType)
            })
            if (x > -1) {
              that.$message.warn(that.$t('请选择回收方式'))
              return
            }
            let y = that.recycleList.findIndex((rl) => {
              return rl.status == 'Y' && isEmpty(rl.recyclingValue, 1)
            })
            if (y > -1) {
              that.$message.warn(that.$t('请输入回收值'))
              return
            }
            let arr = []
            that.recycleList.forEach((l) => {
              arr.push(l)
            })
            querydata.recyclingList = arr
          }
          if (that.dataForm.form == 2 || that.dataForm.form == 3 || that.dataForm.form == 4) {
            let arr = that.elevation.filter((el) => {
              return el.disable
            })
            querydata.bisGoodsMemberTypeList = arr
          }
          querydata.bisGoodsPackageList = []
          // 原材料
          querydata.bisGoodsMaterialList = []
          that.setRawMaterialsTable.dataSource.forEach((col) => {
            if (col.action != that.$t('合计')) {
              querydata.bisGoodsMaterialList.push(col)
            }
          })
          let httpurl = ''
          let method = ''
          if (!that.dataForm.id) {
            httpurl += that.url.add
            method = 'post'
          } else {
            httpurl += that.url.edit
            method = 'put'
          }
          that.confirmLoading = true
          httpAction(httpurl, querydata, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok', res.result)
                if (that.dataForm.id || !that.isContinue || that.isMeal) {
                  that.close()
                } else {
                  that.initDataForm()
                }
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
    handleCancel() {
      that.close()
    },
    changeChargeStatue(e) {
      that.chargeAfter = e.target.checked
    },
    changeRenewalStatue(e) {
      that.renewalAfter = e.target.checked
    },
    addElevation() {
      that.elevation.push({
        memberType: undefined,
        memberTypeAfter: undefined,
        disable: false,
      })
    },
    deleteElevation(i) {
      that.elevation.splice(i, 1)
    },
    editElevation(i) {
      that.$set(that.elevation[i], 'disable', false)
    },
    saveElevation(item, i) {
      if (item.memberType && item.memberTypeAfter) {
        that.$set(that.elevation[i], 'disable', true)
      } else if (!item.memberType) {
        that.$message.warn(that.$t('请选择晋级前会员类型'))
      } else {
        that.$message.warn(that.$t('请选择晋级后会员类型'))
      }
    },
    onSearch(value) {
      let query = {}
      query.state = 'Y'
      if (value) {
        query.name = ',' + value + ','
      }
      getAction('/goods/bisGoodsUnit/list', query).then((res) => {
        if (res.success) {
          that.unitList = res.result.records
        }
      })
    },
    addUnit() {
      that.$refs.unitModal.show()
    },
    updateUnit(res) {
      that.unitList = that.unitList.concat(res)
      that.$set(that.dataForm, 'unit', res.id)
    },
    changeAddState() {
      localStorage.setItem('goodsAddInfo', JSON.stringify({ state: that.isContinue }))
    },
    initDataForm() {
      let value = that.stateDisable
      if (value == 1) {
        that.dataForm = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: '',
          allowMemberDiscount: 'N',
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          species: '1',
          bisGoodsPackageList: [],
          supplierId: '',
          recyclingList: [{ status: 'N' }],
          store: '',
          stock: ''
        }
      }
      if (value == 2) {
        that.dataForm = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: 0,
          allowMemberDiscount: 'N',
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
          bisGoodsPackageList: [],
          freeWithRecharge: false,
        }
        that.chargeAfter = false
        that.elevation = [
          {
            memberType: undefined,
            memberTypeAfter: undefined,
            disable: false,
          },
        ]
        that.renewalAfter = false
        that.renewalList = [
          {
            type: '0',
            renewal: '',
          },
        ]
      }
      if (value == 3) {
        that.dataForm = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: 0,
          allowMemberDiscount: 'N',
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          totalNumber: '1',
          species: '1',
          bisGoodsPackageList: [],
          validityType: '0',
        }
        that.chargeAfter = false
        that.elevation = [
          {
            memberType: undefined,
            memberTypeAfter: undefined,
            disable: false,
          },
        ]
        that.renewalAfter = false
        that.renewalList = [
          {
            type: '0',
            renewal: '',
          },
        ]
      }
      if (value == 4) {
        that.dataForm = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: 0,
          allowMemberDiscount: 'N',
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          species: '1',
          bisGoodsPackageList: [],
          validityType: '0',
          freeWithRecharge: false,
        }
        that.chargeAfter = false
        that.elevation = [
          {
            memberType: undefined,
            memberTypeAfter: undefined,
            disable: false,
          },
        ]
        that.renewalAfter = false
        that.renewalList = [
          {
            type: '0',
            renewal: '',
          },
        ]
      }
      if (value == 8) {
        that.dataForm = {
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: 0,
          allowMemberDiscount: 'N',
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
          bisGoodsPackageList: [],
        }
      }
      if (value == 10) {
        that.dataForm = {
          supplierId: '',
          code: '',
          name: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          allowMemberDiscount: 'N',
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
          bisGoodsPackageList: [],
        }
      }
      if (value == 11) {
        that.dataForm = {
          code: '',
          name: '',
          cost1: '',
          cost: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          allowSale: 'N',
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
        }
      }
      if (value == 12) {
        that.dataForm = {
          code: '',
          name: '',
          cost1: '',
          allowOut: 'N',
          allowWarn: 'N',
          warnNum: 0,
          verifyType: '1',
          cost: '',
          allowMemberDiscount: 'N',
          allowCoin: 'N',
          allowLottery: 'N',
          allowPoints: 'N',
          allowSale: 'N',
          allowIntegral: 'N',
          allowAlottery: 'N',
          authSale: 1,
          state: 'Y',
          limitCycle: '0',
          allowMemberType: '',
          allowDevices: [],
          allowDevice: '',
          allowDeviceTypes: [],
          allowDeviceType: '',
          form: value,
          presentCoin: '0',
          realCoin: '0',
          species: '1',
        }
      }
      that.allowWarnsdisable = true
      that.$refs.code.focus()
      that.edit(that.dataForm)
    },
    changeSelectState(e, key, type){
      if(type == 1){
        this.$set(this.dataForm, key, e.target.checked ? 1 : 0)
      }
      if(type == 2){
        this.$set(this.dataForm, key, e.target.checked ? 'Y' : 'N')
      }
    }
  },
}
</script>
<style scoped>
.bold-font {
  font-weight: bold;
}
/deep/ .detail-upload .ant-upload-list-picture-card-container {
  width: 100%;
  height: 250px;
}
/deep/ .detail-upload .ant-upload-list-picture-card .ant-upload-list-item {
  width: 77% !important;
  height: 100% !important;
}
/deep/ .detail-upload .ant-upload .ant-upload-select .ant-upload-select-picture-card {
  width: 100%;
  height: 250px;
}
/deep/ .detail-upload .ant-upload {
  width: 77% !important;
  height: 100% !important;
}
</style>